<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Contact_model extends CI_Model
{
    public $contact_id;
    public $tel;
    public $phone;
    public $qq;
    public $address;
    public $email;
    public $conpany_name;
    public $fax;
    public $menuid;
    public function __construct()
    {
        parent::__construct();
        $this->load->database();
    }

    public function add_contact($contactModel)
    {
        return  $this->db->insert('contact',$contactModel);
    }

    public function get_first_row_by_menuid($menuid)
    {
        $sql="select * from contact where menuid=$menuid";
        return $this->db->query($sql)->row();
    }
    public function get_first_row()
    {
        $sql="select * from contact";
        return $this->db->query($sql)->row();
    }

    public function get_contact_by_id($contact_id)
    {
        $sql="select * from contact where contact_id=$contact_id";
        return $this->db->query($sql)->row();
    }

    public function update_contact($contactModel)
    {
        $sql="update contact set conpany_name='$contactModel->conpany_name',address='$contactModel->address',qq='$contactModel->qq',tel='$contactModel->tel',fax='$contactModel->fax',email='$contactModel->email',phone='$contactModel->phone' where contact_id=$contactModel->contact_id";
        return $this->db->query($sql);
    }

    public function del_contact($contact_id)
    {
        $sql="delete from contact where contact_id=$contact_id";
        return $this->db->query($sql);
    }
}
?>